package com.malie.myspringboot.mybatis;

import com.malie.myspringboot.common.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MybatisDemo {

    @Autowired
    MybatisDemoMapper mybatisDemoMapper;

    @GetMapping("/demo1")
    public List<UserEntity> Demo1() {
        // 不用resultMap时需写resultType
        List<UserEntity> list = mybatisDemoMapper.findAll();
        return list;
    }

    @GetMapping("/demo2")
    public List<UserEntity> Demo2() {
        //j基本使用
        List<UserEntity> list = mybatisDemoMapper.findAll2();
        return list;
    }

    @GetMapping("/demo3")
    public List<UserEntity> Demo3() {
        //带一个参数 对象属性 不用Param注解
        List<UserEntity> list = mybatisDemoMapper.findAll3(2);
        return list;
    }

    @GetMapping("/demo4")
    public List<UserEntity> Demo4() {
        //带一个参数(对象) Mybatis会 根据实体类(entity)的类型自动识别并匹配javaBean  不用Param注解
        UserEntity userEntity = new UserEntity();
        userEntity.setId(3);
        List<UserEntity> list = mybatisDemoMapper.findAll4(userEntity);
        return list;
    }

    @GetMapping("/demo5")
    public List<UserEntity> Demo5() {
        //带一个参数(对象) 需一一对应  用Param注解
        UserEntity userEntity = new UserEntity();
        userEntity.setId(3);
        List<UserEntity> list = mybatisDemoMapper.findAll5(userEntity);
        return list;
    }
}
